<?php

namespace App\Model\Group;

use App\Component\DeviceIdentity\DeviceUser;
use App\Component\User;
use App\Core\BaseModel;
use App\Core\Exception\DefaultException;
use App\Core\Output;
use App\Model\Member\MemberModel;
use App\Util\CommonHelper;
use App\Util\UserIdentityHelper;
use EasySwoole\Component\Di;
use EasySwoole\ORM\Exception\Exception;
use EasySwoole\Redis\Redis;
use EasySwoole\RedisPool\RedisPool;

/**
 * CREATE TABLE `ss_group_profit` (
 * `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
 * `member_id` int(11) NOT NULL COMMENT '用户id',
 * `child_id` int(11) DEFAULT NULL COMMENT '团队人员id',
 * `profit` decimal(10,2) DEFAULT NULL COMMENT '团队提成总计',
 * `created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT '创建时间',
 * `created_by` varchar(32) NOT NULL DEFAULT '' COMMENT '创建人员账号',
 * `updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
 * `updated_by` varchar(32) NOT NULL DEFAULT '' COMMENT '最后更新人员账号',
 * `is_delete` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除[0:未删除，1：已删除]',
 * `deleted_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT '删除时间',
 * PRIMARY KEY (`id`),
 * UNIQUE KEY `idx_unique` (`member_id`,`child_id`,`deleted_at`),
 * KEY `child_id` (`child_id`)
 * ) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4 COMMENT='团队收益';
 */
/**
 * Class MemberModel
 * @property integer $id
 * @property integer $member_id 用户id
 * @property integer $child_id 团队人员id
 * @property integer $profit 团队提成总计
 */
class GroupProfitModel extends BaseModel
{

    protected $tableName = 'ss_group_profit';

    protected $casts = [
        'id'         => 'integer',
        'member_id'  => 'integer',
        'child_id'   => 'integer',
        'profit'     => 'float',
        'created_at' => 'datetime',
        'created_by' => 'string',
        'updated_at' => 'datetime',
        'updated_by' => 'string',
        'is_delete'  => 'integer',
        'deleted_at' => 'datetime',
    ];

    protected static function onAfterUpdate($model, $res)
    {
        self::delCache('memberScoreCache:');
    }

    protected static function onAfterInsert($model, $res)
    {
        self::delCache('memberScoreCache:');
    }
}
